-
-
Notifications
You must be signed in to change notification settings - Fork 109
docs: Update README to use module imports #581
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lgtm
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Tentative on this, majority of our docs are in CJS and the underlying code is in CJS.
Likewise, CJS is still the default for Node in that it will treat all .js
files as cjs unless the type is explicitly set to module in package.json.
|
||
fastify.register(require('@fastify/multipart')) | ||
fastify.register(multipart) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it's better to await this
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why? I want to understand for my own personal use as well.
@Fdawgs would you not agree that Modules is the way node is headed and the majority of new code is written with modules? I understand that the underlying code is in CJS (and other parts of the docs too) but that wouldn't be a deterrent. If we want to move forward change needs to be incremental and non-breaking! We couldn't possibly update it all at once :) |
Signed-off-by: AlvesJorge <60895482+AlvesJorge@users.noreply.github.com>
I agree with this. Also, each example, considering the diff only, seems to be completely stand alone prior to this proposed change. With this change, each example, subsequent to the first, references a missing variable. |
Maybe. Maybe not. Personally, I find ESM way more trouble than it's worth and a frustrating syntax full stop. So I rarely ever use it. The most common case being to get top level await, but I'd rather wrap everything in an async function than deal with ESM just for that. |
Thank you for sharing your perspective @jsumners, I didn't know this would be so polarizing! I'm unsure what you mean by:
What missing variable are you referring to? |
Note that I have not submitted a review. Thus I have not cast a vote one way or the other.
I think the main repo provides both CJS and ESM through a toggle while viewing the website.
The |
@jsumners The subsequent examples are also missing the |
The fastify/fastify repository’s README provides both ESM and CommonJS examples (please see attached). https://github.com/fastify/fastify?tab=readme-ov-file#example ![]() |
I agree that having ESM examples is important. It’s the default for most frontend tools and is also adopted by many Node.js frameworks, such as Nest.js and Next.js. That said, the most widely used Node.js framework, Express, still documents examples in CJS, and this doesn't seem to be an issue in practice. Although I personally use ESM, I believe consistency and ease of maintenance is more important here. I see a few possible approaches:
|
Hello 👋
As the ESModules are the standard way to import/export modules in javascript, the README examples should reflect that :)